home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / mpss / setupuni.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-20  |  2.2 KB  |  146 lines

  1.  
  2. /*******************************************************************************
  3. ********************************************************************************
  4. ********************************************************************************
  5.  
  6. PERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT
  7. THIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES.
  8.  
  9.         P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988.
  10.  
  11.  
  12. ********************************************************************************
  13. ********************************************************************************
  14. *******************************************************************************/
  15.  
  16. #include "header.h"
  17. #include "planets.h"
  18.  
  19. /*rand number between 0 and X*/
  20. rnd(s,x) 
  21. int s,x;
  22. {
  23. int i;
  24.  
  25. do
  26. {
  27. i=(int)(abs(rand()%100));
  28. }
  29. while ((i<s)||(i>x));
  30. return(i);
  31. }
  32.  
  33. add(xx,y,cc) 
  34.  int xx,y;
  35.  char cc;
  36. {
  37.      char *malloc();
  38.     struct thing *a,*p,*r;
  39.  
  40. if (univ[y]==NULL)
  41.     {
  42.     univ[y]=(struct thing *)malloc(sizeof(struct thing));
  43.     univ[y]->x=xx;
  44.     univ[y]->c=cc;
  45.     univ[y]->next_thing=NULL;
  46.     } else
  47.     {
  48.     r=(struct thing *)malloc(sizeof(struct thing));
  49.     r->x=xx;
  50.     r->c=cc;
  51.  
  52.     a=univ[y]; p=a->next_thing;
  53.     while ((p!=NULL)&&(p->x<=xx)) 
  54.         {
  55.         a=p;
  56.         p=p->next_thing;
  57.         }
  58.     if ((a==univ[y])&&(a->x>xx))
  59.         {
  60.         univ[y]=r;
  61.         r->next_thing=a;
  62.         } else
  63.         {
  64.         a->next_thing=r;
  65.         r->next_thing=p;
  66.         }
  67.     }
  68. }
  69.  
  70. setupuniverse()
  71. {
  72.  
  73. newgame();
  74.  
  75. for (i=0; i<10; ++i)
  76.     players[i]=0;
  77.  
  78. for (i=0; i<918; ++i) 
  79.     {
  80.     univ[i]=NULL;
  81.     }
  82.  
  83. add(225,225,'*');
  84. add(225,675,'*');
  85. add(675,225,'*');
  86. add(675,675,'*');
  87.  
  88. add(680,680,'k');
  89. add(670,670,'k');
  90. add(564,662,'k');
  91. add(470,488,'k');
  92.  
  93. add(498,199,'#');
  94. add(501,197,'#');
  95. add(504,199,'#');
  96. add(498,203,'#');
  97. add(501,205,'#');
  98. add(504,203,'#');
  99.  
  100. add(501,201,'o');
  101.  
  102.  
  103. /*planets*/
  104.  
  105. for (r=0; r<30; ++r)
  106.     {
  107.     /*draw a planet....*/
  108.     add(plan[r].xpos,plan[r].ypos,'O');
  109.     }
  110.  
  111. /*set up stars*/
  112. for (x=100; x<770; x+=60)
  113.     {
  114.     for (y=100; y<770; y+=25)
  115.     {
  116.         do
  117.         {
  118.             i=rnd(0,10);
  119.             j=rnd(0,15);
  120.         }
  121.         while (!(inuniv(x+i,y+j)==NULL));
  122.     k=rnd(0,100);
  123.     if (k<50) 
  124.         add(x+i,y+j,'.'); else
  125.         add(x+i,y+j,'@');
  126.     }
  127.     }
  128. }
  129.  
  130. inuniv(xx,y) 
  131. int xx,y;
  132. {
  133. register struct thing *p;
  134.  
  135. p=univ[y];
  136.  
  137. while (p!=NULL)
  138.     {
  139.     if (p->x==xx) return(p->c);
  140.     p=p->next_thing;
  141.     }
  142.  
  143. return(NULL);
  144. }
  145.  
  146.